﻿using GCC.APIContainer.WSManager;
using GCC.Container.Abstracts;

namespace GCC.APIContainer
{
    /// <summary>
    /// 容器上下文
    /// </summary>
    public partial class GCCContext : AbsGCCContext
    {

        /// <summary>
        /// 获取所有的在线用户ID
        /// </summary>
        /// <returns></returns>
        public override List<long> GetAllUserID()
        {
            return GCCTextWSPool.Instance.GetAllUserID();
        }

        /// <summary>
        /// 給某个用户发送文本的消息
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="text">文本</param>
        public override void SendTextMessageToUser(long uid, string text)
        {
            GCCTextWSPool.Instance.SendTextMessageToUser(uid, text);
        }

        /// <summary>
        /// 给所有在线的人广播
        /// </summary>
        /// <param name="text"></param>
        public override void BoardCastTextMessage(string text)
        {
            GCCTextWSPool.Instance.BoardCastTextMessage(text);
        }

        /// <summary>
        /// 获取用户的文本websocket客户端链接
        /// </summary> 
        /// <param name="uid">用户ID</param>
        /// <returns></returns> 
        public override List<AbsWebsocketClient> GetUserWSClient<T>(long uid)
        {
            var res = new List<AbsWebsocketClient>();
            if (typeof(T) == typeof(string))
            {
                GCCTextWSPool.Instance.GetUserTextWSInfo(uid).ForEach(item =>
                {
                    res.Add(item);
                });
            }

            return res;

        }

        /// <summary>
        /// 强制某个类型的端下线
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="clientID">端ID不传就是全部</param>
        public override void ForcedOffline<T>(long uid, string? clientID)
        {
            if (typeof(T) == typeof(string))
            {
                GCCTextWSPool.Instance.ForcedOffline(uid, clientID);
            }
        }

        /// <summary>
        /// 給某个用户的某个端发送文本的消息
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="clientID">用户clientID</param>
        /// <param name="text">文本</param>
        public override void SendTextMessageToUserClient(long uid, string clientID, string text)
        {
            GCCTextWSPool.Instance.SendTextMessageToUserClient(uid, clientID, text);
        }

    }
}
